package com.bolong.gmgc.timer.cash_check;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.TimerTask;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.bolong.gmgc.bean.record.Watchhouse;
import com.bolong.gmgc.dao.record.CashcheckMapper;
import com.bolong.gmgc.dao.record.WatchhouseMapper;

/**
 * 在 TimerManager 这个类里面，大家一定要注意 时间点的问题。如果你设定在凌晨2点执行任务。但你是在2点以后
 *发布的程序或是重启过服务，那这样的情况下，任务会立即执行，而不是等到第二天的凌晨2点执行。为了，避免这种情况
 *发生，只能判断一下，如果发布或重启服务的时间晚于定时执行任务的时间，就在此基础上加一天。
 * @author wls
 *
 */

@Component
public class Cash_checkTimerTask extends TimerTask {
    private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Autowired
    private CashcheckMapper cashcheckmapper;
    @Autowired
    private WatchhouseMapper watchhousemappers;
    @Override
    public void run() {
        try {
        	System.out.println("执行前是否能够输出");
        	List<Watchhouse> selectallwatchhouse = watchhousemappers.selectallwatchhouse();
        	for (Watchhouse watchhouse : selectallwatchhouse) {
        		//如果昨天 该岗亭上班人数
        		int c=watchhousemappers.findwatchhouse_cash_empcount(watchhouse.getId());
        		if(c>0){
        			if(c == 1){
        				cashcheckmapper.exculsqlone(watchhouse.getId(),watchhouse.getParkId());
        			}else{
        				cashcheckmapper.exculsql(watchhouse.getId(),watchhouse.getParkId());
        			}
        		}
			}
            System.out.println("执行当前时间"+formatter.format(Calendar.getInstance().getTime()));
            
        } catch (Exception e) {
        	e.printStackTrace();
            System.out.println("-------------解析信息发生异常--------------");
        }
    }
     
}
